package com.search.config;

import org.elasticsearch.client.RequestOptions;
import org.elasticsearch.client.RestHighLevelClient;
import org.elasticsearch.client.indices.CreateIndexRequest;
import org.elasticsearch.client.indices.CreateIndexResponse;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.junit4.SpringRunner;

import java.io.IOException;
@SpringBootTest
@RunWith(SpringRunner.class)
public class test {

    @Autowired
    private RestHighLevelClient restHighLevelClient;

    /**
     * 新建索引
     * @throws Exception
     */
    @Test
    public void testCreateIndex() throws IOException {
        //创建索引请求
        CreateIndexRequest request = new CreateIndexRequest("dome_one");
        System.out.println(restHighLevelClient);
        //这里是通过客户端，然后传递请求， RequestOptions.DEFAULT（这个是默认的，是es里面的，可以查看源码）
        CreateIndexResponse response = restHighLevelClient.indices().create(request, RequestOptions.DEFAULT);
        System.out.println(response);
    }

}
